<?php

require_once __DIR__ . '/../Locale.php'; // only needed for PHPUnit

class Rsj_Locale_Zend extends Rsj_Locale
{
    public function getTypeOfLocaleProcessor()
    {
        return "Zend Framework 1 Locale";
    }

    /**
     * Zend_Locale requires language part only ('en', not 'en_US')
     */
    protected $_wordpressLanguage = null;

    protected function getWordpressLanguage()
    {
        if ( is_null( self::$_wordpressLanguage ) ) {
            $zendLocale = new Zend_Locale( $this->_locale );
            self::$_wordpressLanguage = $zendLocale->getLanguage();
        }

        return self::$_wordpressLanguage;
    }

    protected $_zendCurrency = null;

    protected function getZendCurrency( $currency = 'USD' )
    {
        if ( is_null( self::$_zendCurrency ) ) {
            $zendLocale = new Zend_Locale( $this->_locale );
            self::$_zendCurrency = new Zend_Currency(
                            array(
                                'locale' => $wordpressLocale,
                                'currency' => $currency,
                                'display' => Zend_Currency::USE_NAME,
                                'position' => Zend_Currency::STANDARD
                            )
            );
        }

        return self::$_zendCurrency;
    }

    public function getDisplayLanguage( $languageCode )
    {
        $makeSureItsLanguage = strtolower( $languageCode );

        return Zend_Locale::getTranslation( $makeSureItsLanguage, 'language', self::getWordpressLanguage() );
    }

    public function formatCurrency( $value, $currency, $type = 'ignored' )
    {
        // does not work...
//			return self::getZendCurrency($currency)->toCurrency($value);
        return Zend_Locale_Format::toNumber( $value, array( 'locale' => $this->_locale ) ) . " ($currency)";
    }

    public function format( $value, $type = 'ignored' )
    {
        return Zend_Locale_Format::toNumber( $value, array( 'locale' => $this->_locale ) );
    }

}
